package com.zhihesj.anan.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhihesj.anan.system.entity.Dept;
import com.zhihesj.anan.system.mapper.DeptMapper;
import com.zhihesj.anan.system.service.DeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhihesj.anan.system.vo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author anan
 * @since 2020-07-25
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private DeptMapper deptMapper;


    @Override
    public List<Dept> selectPage(DeptVo deptVo) {
        QueryWrapper<Dept> wrapper = new QueryWrapper<>();
        if (deptVo.getParentId()>=0){
            wrapper.eq("parent_id", deptVo.getParentId());
        }
        if (!StrUtil.hasEmpty(deptVo.getDeptName())) {
            wrapper.like("dept_name", deptVo.getDeptName());
        }

        IPage<Dept> iPage =null;
        if (deptVo.getPage() != null) {
            iPage = new Page<>(deptVo.getPage(), deptVo.getLimit());
            return deptMapper.selectPage(iPage, wrapper).getRecords();
        } else {
            return deptMapper.selectList(wrapper);

        }
    }
}
